﻿<UserControl x:Class="RSSFeedReader.Views.PostView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:res="clr-namespace:RSSFeedReader.Resources;assembly=RSSFeedReader.Resources"
             mc:Ignorable="d"
             d:DesignWidth="379"
             d:DesignHeight="248">

    <UserControl.Resources>
        
        <!--Storyboard for mouse enter and leave on feeds-->
        <Storyboard x:Key="OnMouseOverFeeds">
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#00FFFFFF" />
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#7FA1A1A1" />
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#BF333333" />
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#BF000000" />
            </ColorAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Key="OnMouseLeaveFeeds">
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00"
                                     Value="#00FFFFFF" />
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#00FFFFFF" />
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00"
                                     Value="#7FA1A1A1" />
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#00A1A1A1" />
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00"
                                     Value="#BF333333" />
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#00333333" />
            </ColorAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames BeginTime="00:00:00"
                                          Storyboard.TargetName="border"
                                          Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00"
                                     Value="#BF000000" />
                <SplineColorKeyFrame KeyTime="00:00:00.7000000"
                                     Value="#00000000" />
            </ColorAnimationUsingKeyFrames>
        </Storyboard>

        <DataTemplate x:Key="PostsTemplate">
            <Grid Height="50"
                  Cursor="Hand"
                  x:Name="Root">
                <Grid.ToolTip>
                    <TextBlock MaxWidth="400"
                               TextWrapping="Wrap"
                               Text="{Binding Path=Description}" />
                </Grid.ToolTip>
                <Border BorderBrush="#00FFFFFF"
                        BorderThickness="1,1,1,1"
                        CornerRadius="4,4,4,4"
                        x:Name="border">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1"
                                             StartPoint="0.5,0">
                            <GradientStop Color="#00000000"
                                          Offset="0" />
                            <GradientStop Color="#00333333"
                                          Offset="1" />
                            <GradientStop Color="#00A1A1A1"
                                          Offset="0.504" />
                        </LinearGradientBrush>
                    </Border.Background>

                    <Grid>
                        <StackPanel Orientation="Vertical"
                                    Grid.ColumnSpan="1"
                                    Grid.Column="1">
                            <TextBlock Text="{Binding Path=Title}"
                                       Foreground="#FFFFFFFF"
                                       x:Name="ChannelTitle"
                                       TextWrapping="Wrap"
                                       MaxWidth="200" />
                        </StackPanel>
                    </Grid>
                </Border>
                <Rectangle Stroke="{x:Null}"
                           HorizontalAlignment="Stretch"
                           x:Name="rectangle"
                           VerticalAlignment="Top"
                           Margin="0,0.206,0,0"
                           Height="26.594">
                    <Rectangle.Fill>
                        <LinearGradientBrush EndPoint="0.5,1"
                                             StartPoint="0.5,0">
                            <GradientStop Color="#72FFFFFF"
                                          Offset="0" />
                            <GradientStop Color="#00FFFFFF"
                                          Offset="0.996" />
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </Grid>
            <DataTemplate.Triggers>

                <Trigger Property="IsMouseOver"
                         Value="True"
                         SourceName="Root">
                    <Trigger.ExitActions>
                        <BeginStoryboard Storyboard="{StaticResource OnMouseLeaveFeeds}"
                                         x:Name="OnMouseLeaveFeeds_BeginStoryboard" />
                    </Trigger.ExitActions>
                    <Trigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource OnMouseOverFeeds}"
                                         x:Name="OnMouseOverFeeds_BeginStoryboard" />
                    </Trigger.EnterActions>
                </Trigger>

            </DataTemplate.Triggers>
        </DataTemplate>

    </UserControl.Resources>

    <Grid>
        <ListBox ItemsSource="{Binding Path=CurrentChannel.Posts}"
                 Grid.RowSpan="2"
                 IsSynchronizedWithCurrentItem="True"
                 ItemTemplate="{StaticResource PostsTemplate}"
                 ItemContainerStyle="{DynamicResource FeedItemStyle}"
                 ItemsPanel="{DynamicResource FeedViewItemTemplate}"
                 BorderBrush="{x:Null}" />
        <TextBlock HorizontalAlignment="Center"
                   VerticalAlignment="Top"
                   x:Name="errorTextBlock"
                   FontSize="16"
                   Foreground="#FFFFFFFF">
            <TextBlock.Style>
                <Style>
                    <Setter Property="TextBlock.Text"
                            Value="{x:Static res:Strings.PostView_NoChannelSelected}" />
                    <Setter Property="TextBlock.Visibility"
                            Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=CurrentChannel.Posts/Title}"
                                     Value="{x:Null}">
                            <Setter Property="TextBlock.Visibility"
                                    Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
    </Grid>

</UserControl>
